package com.meixiang.dialog;

import android.view.View;

import com.meixiang.R;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 选择拍照或者相册上传头像的Dialog
 *
 * @author LZRUI
 */
public class SelectPhotoDialogFragment extends BaseDialogFragment {

    public static String TAG = "SelectPhotoDialogFragment";
    private PhotoSelectListener listener;

    public SelectPhotoDialogFragment setPhotoSelectListener(PhotoSelectListener photoSelectListener) {
        this.listener = photoSelectListener;
        return this;
    }

    public static SelectPhotoDialogFragment newInstance() {
        return new SelectPhotoDialogFragment();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        ButterKnife.unbind(this);
    }

    @Override
    protected int setFragmentViewId() {
        return R.layout.dialog_select_photo;
    }

    @Override
    protected void initView(View rootView) {
        ButterKnife.bind(this, rootView);
    }

    @Override
    protected void initData() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.tv_take_photo, R.id.tv_photo_album, R.id.tv_cancel})
    public void onClick(View view) {
        switch (view.getId()) {
            // 拍照上传
            case R.id.tv_take_photo:
                if (listener != null) {
                    listener.takePhoto();
                }
                dismiss();
                break;
            // 相册选择
            case R.id.tv_photo_album:
                if (listener != null) {
                    listener.selectPhotoAlbum();
                }
                dismiss();
                break;
            // 取消
            case R.id.tv_cancel:
                dismiss();
                break;
        }
    }

    public interface PhotoSelectListener {
        /**
         * 拍照
         */
        void takePhoto();

        /**
         * 选择相册
         */
        void selectPhotoAlbum();
    }
}
